﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;

namespace Web.admin.UserManage.Users
{
    public partial class ModifyPwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 确认事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            SitePrincipal user = (SitePrincipal)Context.User;
            string oldPwd = OldPwd.Text.Trim();
            string newPwd = NewPwd.Text.Trim();
            string confirmPwd = ConfirmPwd.Text.Trim();
            if (string.IsNullOrEmpty(oldPwd) || string.IsNullOrEmpty(newPwd) || string.IsNullOrEmpty(confirmPwd))
            {
                Response.Write("<script>alert('不允许有空项，请检查所输入的内容')</script>");
                return;
            }
            else if(newPwd!=confirmPwd)
            {
                Response.Write("<script>alert('两次输入的密码不一致')</script>");
                return;
            }
            else
            {
                SiteIdentity si = user.Identity as SiteIdentity;
                if (si.Password != oldPwd)
                {
                    Response.Write("<script>alert('原密码错误')</script>");
                }
                else
                {
                    BLL.TeacherService teacherservice = new TeacherService();
                    BoTeachers teacherRole = teacherservice.GetTeacher(si.UserID);
                    teacherRole.TEA_PASSWORD = newPwd;
                    teacherservice.UpdateTeacher(teacherRole);
                    Response.Write("<script>alert('修改成功');</script>");
                }
            }
            
        }
    }
}